import rx.Observable;

import java.awt.*;

/**
 * Created by czx on 2017/2/26.
 */
public class CustomOperatorTest {

    void testCustomAverage(){
        Observable.just(3,4,5,6)
                .scan(new AverageAcc(0,0),
                        (acc,next)->new AverageAcc(acc.sum+next,acc.count+1))
                .map(v->v.sum/v.count)
                .subscribe(v->System.out.println("average:"+v));
    }

    void testCustomAverage2(){
        Observable.just(1,2,3,4,5)
                .compose(new RunningAverage())
                .subscribe(System.out::println);
    }

    public static void main(String[] args) {
        CustomOperatorTest cot = new CustomOperatorTest();
//        cot.testCustomAverage();
        cot.testCustomAverage2();
    }

}
